package com.vpx.server.framework.authority;

import com.vpx.server.bean.info.base.UserInfo;
import com.vpx.server.framework.base.SessionContext;
import com.vpx.server.framework.exception.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author lihui
 * @title: vpx
 * @module TODO
 * @description: session工具类
 * @date 2021/9/12 12:36
 */
public class SessionUtil {
    static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
    private static final ThreadLocal<SessionInfo> THREAD_LOCAL = new InheritableThreadLocal<SessionInfo>();

    public static SessionInfo getSession() {
        return THREAD_LOCAL.get();
    }

    public static void init(SessionInfo session) {

        StackTraceElement[] traceElements = Thread.currentThread().getStackTrace();
        StackTraceElement last = traceElements[traceElements.length - 1];
        logger.info("last invoick {}", last.getClassName());

        THREAD_LOCAL.set(session);
    }

    public static void clear() {
        THREAD_LOCAL.remove();
    }
}
